/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.dao.hibernate;

import com.minierp.dao.ReceiveBillItemDao;
import com.minierp.dao.hibernate.BaseDaoImpl;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

public class ReceiveBillItemDaoImpl extends BaseDaoImpl
		implements
			ReceiveBillItemDao {
	public List getListByReceiveBill(long billId) {
		String sql = "from com.minierp.model.ReceiveBillItem s where s.billId="
				+ billId + " order by s.id";
		return this.getHibernateTemplate().find(sql);
	}

	public List getListForPrinLitt(long billId) {
		String sql = "select i,bb.orderDate,bb.deliverDate from com.minierp.model.ReceiveBillItem i,com.minierp.model.BusinessBill bb where i.billId="
				+ billId + " and i.businessBillId=bb.id" + " order by i.id";
		return this.getHibernateTemplate().find(sql);
	}

	public List getListByBusinessBill(long billId) {
		String sql = "select b,s from com.minierp.model.ReceiveBill b ,com.minierp.model.ReceiveBillItem s where b.id=s.billId and s.businessBillId="
				+ billId + " and b.enabled=\'Y\'" + " order by s.id";
		return this.getHibernateTemplate().find(sql);
	}

	public int delete(final long id) {
		Object obj = this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						String hql = "delete com.minierp.model.ReceiveBillItem where id=:id";
						return new Integer(session.createQuery(hql)
								.setLong("id", id).executeUpdate());
					}
				});
		return ((Integer) obj).intValue();
	}

	public int deleteByReceiveBillId(final long billId) {
		Object obj = this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						String hql = "delete com.minierp.model.ReceiveBillItem where billId=:billId";
						return new Integer(session.createQuery(hql)
								.setLong("billId", billId).executeUpdate());
					}
				});
		return ((Integer) obj).intValue();
	}
}